package com.xwm93up.basic;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: desc
 * @Author: xwm93up
 * @Since: 2023/2/25 13:45
 */
public class GenericDemo<T> {

    @Test
    public void test1() {
        List arrayList = new ArrayList<>();
        arrayList.add("zhangSan");
        arrayList.add(100);

        for (int i = 0; i < arrayList.size(); i++) {
            String item = (String) arrayList.get(i);
            System.out.println("test=====" + item);
        }
    }

    private T value;

    public GenericDemo(T value) {
        this.value = value;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }


    public static void generic(List<?> data) {
        System.out.println("Test zhangSan:" +data.get(0));
    }

    public static void main(String[] args) {
        List<String> name = new ArrayList<String>();
        List<Integer> age = new ArrayList<Integer>();
        List<Number> number = new ArrayList<Number>();

        name.add("zhangSan");
        age.add(12);
        number.add(342);
        generic(name);
        generic(age);
        generic(number);
    }
}
